<?php

/**
 * Flammable - A CRUD model enhancer for CodeIgniter
 * 
 * @author  Michael Quinn
 * @version 1.0.0
 * @license Apache 2.0 License
 */
class FlammableModel extends Model
{
    private $table_name;
    private $primary_key = 'id';
    private $objects;
    private $qty;

    function __construct($table_name)
    {
        $this->table_name = $table_name;

        parent::__construct();

        $this->objects = array();
    }

	/**
	 * @package Flammable
	 * 
	 * @return bool
	 */
    public function create($object)
    {
        return $this->db->insert($this->table_name, $object);
    }

	/**
	 * @package Flammable
	 * 
	 * @return array
	 */
    public function read()
    {
        $query = $this->db->get($this->table_name);

        foreach ($query->result() as $row) 
        {
            $this->objects[] = $row;
        }
        return $this->objects;
    }

	/**
	 * @package Flammable
	 * 
	 * @return bool
	 * @param  object $object
	 */
    public function update($object)
    {
        $this->db->where($this->primary_key, $object->id);
        return $this->db->update($this->table_name, $object);		
    }

	/**
	 * @package Flammable
	 * 
	 * @return bool 
	 * @param  object $object
	 */
    public function delete($object)
    {
        $this->db->where($this->primary_key, $object->id);
        return $this->db->delete($this->table_name);
    }

}
